Numerical Integration (Quadrature)


Numerical Integration (Quadrature)

It is a set of methods to compute the numerical value of a definite integral. The most common methods are the Trazpezoidal and Simpson's formula.
Es un conjunto de métodos para calcular el valor numérico de una integral definida. Los métodos más comunes son el del trapecio y la fórmula de Simpson.

Problem 1
Cree a program called IntegralTest using Wintempla to compute the integral of y = sin( x) from 0 to 3.1416.
Cree un programa llamado IntegralTest usando Wintempla para calcular la integral de y = sin( x) desde 0 a 3.1416.

IntegralTestRun

IntegralTest.h
#pragma once //______________________________________ IntegralTest.h
#include "Resource.h"
class IntegralTest: public Win::Dialog, public Math::IFunction
{
public:
     IntegralTest()
     {
     }
     ~IntegralTest()
     {
     }
     void UpdateValues();
     //______________________________________ Math::IFunction
     double EvaluateFunc(const double x);
     ...
};


IntegralTest.cpp
...
void IntegralTest::Window_Open(Win::Event& e)
{
     //________________________________________________________ sldSteps
     sldSteps.SetRange(1, 100);
     sldSteps.Position = 25;
     tbxSteps.IntValue = 25;
     UpdateValues();
}

void IntegralTest::sldSteps_Hscroll(Win::Event& e)
{
     const int position = sldSteps.HasPositionChanged();
     if (position < 0) return;
     tbxSteps.IntValue = position;
     UpdateValues();
}

double IntegralTest::EvaluateFunc(const double x)
{
     return sin(x);
}

void IntegralTest::UpdateValues()
{
     const int N = tbxSteps.IntValue;
     const double a = 0.0;
     const double b = M_PI;
     double error = 0.0;
     tbxSimpson.Text = Sys::Convert::ToString(Math::NumericIntegration::Simpson(*this, a, b, error), L"%.12f");
     tbxSimpson1_3.Text = Sys::Convert::ToString( Math::NumericIntegration::Simpson(*this, a, b, N, error), L"%.12f");
     tbxSimpson3_8.Text = Sys::Convert::ToString(Math::NumericIntegration::Simpson3_8(*this, a, b, N), L"%.12f");
     tbxClenshaw.Text = Sys::Convert::ToString(Math::NumericIntegration::ClenshawCurtis(*this, a, b, N), L"%.12f");
     tbxAdaptiveSimpson.Text = Sys::Convert::ToString(Math::NumericIntegration::AdaptiveSimpson(*this, a, b, 1.e-10, 100), L"%.12F");
}



© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home